using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Hostal.Bussines.Entities;

namespace Hostal.Bussines.Repository.Mapping
{
    public class DetalleFacturaMap : EntityTypeConfiguration<DetalleFactura>
    {
        public DetalleFacturaMap()
        {
            // Primary Key
            this.HasKey(t => new { t.IdFactura, t.IdHuesped });

            // Properties
            this.Property(t => t.IdFactura)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.IdHuesped)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("DetalleFactura");
            this.Property(t => t.IdFactura).HasColumnName("IdFactura");
            this.Property(t => t.IdHuesped).HasColumnName("IdHuesped");
            this.Property(t => t.cantidad).HasColumnName("cantidad");
            this.Property(t => t.PUnitario).HasColumnName("PUnitario");
            this.Property(t => t.Monto).HasColumnName("Monto");

            // Relationships
            this.HasRequired(t => t.Factura)
                .WithMany(t => t.DetalleFacturas)
                .HasForeignKey(d => d.IdFactura);
            this.HasRequired(t => t.Huesped)
                .WithMany(t => t.DetalleFacturas)
                .HasForeignKey(d => d.IdHuesped);

        }
    }
}
